﻿using CommonServiceLocator;
using Jn698._45GWTool.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Jn698._45GWTool.Settings
{
    internal class CommSettings:ConfigurationSection
    {
        public static CommSettings Instanse { get; }=App.Current.Cfg.GetSection("commSettings") as CommSettings;

        [ConfigurationProperty("SelectedCombType",DefaultValue="GPRS")]
        public string SelectedCombType
        {
            get => (string)this["SelectedCombType"];
            set
            {
                this["SelectedCombType"] = value; 
                if (value.Equals("GPRS"))
                {
                    //TbPortIndex = 3;
                    ServiceLocator.Current.GetInstance<CommViewModel>().TbPortIndex = "2";
                    ServiceLocator.Current.GetInstance<CommViewModel>().TbComm = "端口号：";
                }
                else
                {
                    ServiceLocator.Current.GetInstance<CommViewModel>().TbPortIndex = "0";
                    ServiceLocator.Current.GetInstance<CommViewModel>().TbComm = "串口号：";
                }
            }
        }

        [ConfigurationProperty("SelectedCom", DefaultValue = 0)]
        public int SelectedCom
        {
            get => (int)this["SelectedCom"];
            set => this["SelectedCom"] = value;
        }

        [ConfigurationProperty("TbPortIndex", DefaultValue = 0)]
        public int TbPortIndex
        {
            get => (int)this["TbPortIndex"];
            set => this["TbPortIndex"] = value;
        }

        [ConfigurationProperty("SelectedBaud", DefaultValue = 0)]
        public int SelectedBaud
        {
            get => (int)this["SelectedBaud"];
            set => this["SelectedBaud"] = value;
        }
        
        [ConfigurationProperty("SelectedPort", DefaultValue = 22070)]
        public int SelectedPort
        {
            get => (int)this["SelectedPort"];
            set => this["SelectedPort"] = value;
        }

        [ConfigurationProperty("SelectedDataBit", DefaultValue = 0)]
        public int SelectedDataBit
        {
            get => (int)this["SelectedDataBit"];
            set => this["SelectedDataBit"] = value;
        }

        [ConfigurationProperty("SelectedStopBit", DefaultValue = "1")]
        public string SelectedStopBit
        {
            get => (string)this["SelectedStopBit"];
            set => this["SelectedStopBit"] = value;
        }

        [ConfigurationProperty("SelectedParity", DefaultValue = "偶校验")]
        public string SelectedParity
        {
            get => (string)this["SelectedParity"];
            set => this["SelectedParity"] = value;
        }

    }
}
